package com.eastfair.messagecenter.exceptioncode;

import com.eastfair.annotation.base.LanguageTypeEnum;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.core.exception.code.BaseExceptionCode;

/**
 * 场馆服务后台错误码.
 * AABBBCCC   AA(12)  系统编号   BBB 模块    CCC 具体异常
 * 模块编号
 * 展会：001
 * 服务商：002
 * 服务：003
 *
 * @author dqq
 * @date 2022 /7/14
 */
public enum MessageServiceExceptionCode implements BaseExceptionCode {

    /**
     * 客户端
     */
    CLIENT_BAD_PARAMETERS(15003, "客户端参数错误", ""),
    TEMPLATE_NOT_FOUND(15004, "找不到模板或模板已被删除", ""),
    TOO_MANY_RECEIVER(15005, "传入的接收者大于100个", ""),

    /**
     * 系统
     */
    SERVICE_ERROR(15006, "服务执行异常", ""),
    RESOURCE_NOT_FOUND(15007, "资源不存在", ""),


    /**
     * pipeline
     */
    CONTEXT_IS_NULL(15008, "流程上下文为空", ""),
    BUSINESS_CODE_IS_NULL(15009, "业务代码为空", ""),
    PROCESS_TEMPLATE_IS_NULL(15010, "流程模板配置为空", ""),
    PROCESS_LIST_IS_NULL(15011, "业务处理器配置为空", ""),

    SEND_USER_ISNULL(15012, "发送目标为空", ""),

    SEND_CHANNEL_ISNULL(15013, "发送渠道为空", ""),

    SEND_CONTENT_ISNULL(15014, "发送消息为空", ""),

    SEND_TEMPLATE_ISNULL(15015, "模板ID为空", ""),


    TEMPLATE_AGAIN(15016, "模板已存在", ""),
    ;
    private final int code;
    /**
     * 中文消息
     */
    private String msg;
    /**
     * 英文消息
     */
    private String enMsg;

    MessageServiceExceptionCode(int code, String msg, String enMsg) {
        this.code = code;
        this.msg = msg;
        this.enMsg = enMsg;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        //中英文切换
        if (LanguageTypeEnum.CN.name().equals(ContextUtil.getLanguageType())) {
            //中文
            return msg;
        } else if (LanguageTypeEnum.EN.name().equals(ContextUtil.getLanguageType())) {
            //英文
            return enMsg;
        }
        return msg;
    }


    /**
     * Build venue booking exception code.
     *
     * @param msg   the msg
     * @param param the param
     * @return the venue booking exception code
     */
    public MessageServiceExceptionCode build(String msg, Object... param) {
        this.msg = String.format(msg, param);
        return this;
    }

    /**
     * Param venue booking exception code.
     *
     * @param param the param
     * @return the venue booking exception code
     */
    public MessageServiceExceptionCode param(Object... param) {
        msg = String.format(msg, param);
        return this;
    }
}